package com.asynctm.android.socialnetwork.activity;

import java.util.List;

import twitter4j.Status;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.asynctm.android.R;

/**
 * Adapter para la lista de tweets
 * 
 * @author rockdrigo
 */
public class TweetsListAdapter extends BaseAdapter {

	private List<Status> tweets;
	
	private Context context;
	
	private LayoutInflater layoutInflater;
	
	public TweetsListAdapter(Context context, List<Status> tweets) {
		this.context = context;
		this.tweets = tweets;
		this.layoutInflater = LayoutInflater.from(this.context);
	}
	
	public int getCount() {
		return tweets.size();
	}

	public Object getItem(int location) {
		return tweets.get(location);
	}

	public long getItemId(int location) {
		return location;
	}

	public View getView(int location, View convertView, ViewGroup viewGroup) {
		TweetListItemViewHolder tweetListItemViewHolder = null;
		Status tweet = tweets.get(location);
		View v = convertView;
		if(v == null) {
			v = layoutInflater.inflate(R.layout.tweet_list_item, null);
			tweetListItemViewHolder = new TweetListItemViewHolder(v);
			v.setTag(tweetListItemViewHolder);
		} else {
			tweetListItemViewHolder = (TweetListItemViewHolder) v.getTag();
		}
		tweetListItemViewHolder.populate(tweet);
		return v;
	}

}
